<template>
  <el-dialog title="设置角色" :visible="showDialog" @close="close">
    <el-checkbox-group v-model="checkList">
      <el-checkbox
        v-for="item in allRole"
        :key="item.id"
        :label="item.id"
      >{{ item.title }}</el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <el-row type="flex" justify="center">
        <el-button type="primary" size="small" @click="submit">确定</el-button>
        <el-button size="small" @click="close">取消</el-button>
      </el-row>
    </template>
  </el-dialog>
</template>

<script>
// import { getRoleById } from '@/api/setting'
import { getEmployeeInfoById } from '@/api/employees'
import { getRolesListById } from '@/api/setting'
import { editEmployeeInfo } from '@/api/employees'
export default {
  props: {
    showDialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      checkList: [],
      allRole: [],
      roleId: ''
    }
  },
  async created() {
    // 获取角色列表
    const res = await getRolesListById(this.roleId)
    this.allRole = res
    // console.log(32, res)
  },
  methods: {
    // 提交
    async submit() {
      await editEmployeeInfo({
        id: this.roleId,
        roles: this.checkList
      })
      this.close()
    },
    // 根据ID获取角色
    async getRole(id) {
      this.roleId = id
      const res = await getEmployeeInfoById(id)
      this.checkList = res.roles.map(item => item.id)
    },
    close() {
      this.checkList = []
      this.$emit('update:showDialog', false)
    }
  }
}
</script>

<style>

</style>
